package i;

import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;

//创建类

public class data extends ex{
    String name;                                 //内容
    String Class;
    String password = "654321";
    ArrayList<String> array = new ArrayList<>();

    public void getName(String name) {
        this.name = name;
    }

    public void getClass(String Class) {
        this.Class = Class;
    }

    public void printData() {                      //方法
        System.out.println("姓名：" + name);
        System.out.println("班级：" + Class);
    }

    public int login(String pass) {             //继承的变量应用
        String password = "123456789";
        if (super.password.equals(pass))
            return 1;
        else if(this.password.equals(pass))
            return 1;
        else if(password.equals(pass))
            return 1;
        else
            return 0;
    }

    public void help() {
        System.out.println("如果需要改姓名，输入:名字");
        System.out.println("如果需要改班级，输入：班级");
        System.out.println("如果需要查看数据，输入：查看");
        System.out.println("如果要退出程序，输入：退出");
        System.out.println("如果要遍历某个字符串，输入：遍历");
        System.out.println("如果需要统计字符数量，请输入：统计");
        System.out.println("如果需要向存储内容添加字符，请输入：添加");
        System.out.println("如果需要反转字符，请输入：反转");
        System.out.println("如果想启动ArrayList模式，请输入：ArrayList");
        System.out.println("如果想存储信息，请输入：存储");
    }

    public void separate() {
        Scanner sc = new Scanner(System.in);
        System.out.println("您需要遍历哪个选项？（名字  班级）");
        String input = sc.next();
        if (input.equals("名字")) {
            for (int i = 0; i < name.length(); i++) {
                System.out.println(name.charAt(i));                        //charAt的应用
            }                                                              //主要是用来查看string中某个位置的字符
        } else if (input.equals("班级")) {
            for (int i = 0; i < Class.length(); i++) {
                System.out.println(Class.charAt(i));
            }
        } else {
            System.out.println("输入错误指令");
        }
    }

    public void plus() {
        Scanner sc = new Scanner(System.in);                               //stringBuilder的应用
        System.out.println("请输入要加长的字符");                             //主要有append，reverse，和toString
        String plus = sc.next();
        if (plus.equals("名字")) {
            System.out.println("请输入要添加的字符");
            StringBuilder sb = new StringBuilder(name);
            sb.append(sc.next());
            name = sb.toString();
            System.out.println("现在修改为： " + name);
        } else if (plus.equals("班级")) {
            System.out.println("请输入要添加的字符");
            StringBuilder sb = new StringBuilder(Class);
            sb.append(sc.next());
            Class = sb.toString();
            System.out.println("现在修改为： " + Class);
        } else
            System.out.println("输入指令有误");
    }

    public void reverse() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要反转的字符");
        String plus = sc.next();
        if (plus.equals("名字")) {
            StringBuilder sb = new StringBuilder(name);
            sb.reverse();
            name = sb.toString();
            System.out.println("现在修改为： " + name);
        } else if (plus.equals("班级")) {
            StringBuilder sb = new StringBuilder(Class);
            sb.reverse();
            Class = sb.toString();
            System.out.println("现在修改为： " + Class);
        } else
            System.out.println("输入指令有误");
    }

    public void Arraylist() {
        Scanner sc = new Scanner(System.in);
        int i,t;
        String text;
        boolean w = true;
        array.add("hello");
        array.add("world");
        array.add("林子祺");
        array.add("shit");
        System.out.println(array);
        while (w) {
            System.out.println("请输入指令，如需要帮助，输入：帮助");
            String input = sc.next();
            switch (input) {
                case "查看元素":
                    System.out.println(array);
                    System.out.println("元素数量为："+array.size());
                    break;
                case "删除指定位置字符":
                    System.out.println("请输入位置(int)");
                    i = sc.nextInt();
                    if (i < 0 & i >= array.size()) {
                        System.out.println("输入错误位置");
                        break;
                    }
                    else {
                        System.out.println("已移除该位置字符为"+array.remove(i)+"的元素");
                        break;
                    }
                case "删除指定字符":
                    System.out.println("请输入字符(String)");
                    text = sc.next();
                    System.out.println("删除操作结果："+array.remove(text));
                    break;
                case "修改指定位置字符":
                    System.out.println("请输入位置(int)");
                    i = sc.nextInt();
                    if (i < 0 & i >= array.size()) {
                        System.out.println("输入错误位置");
                        break;
                    }
                    else {
                        System.out.println("请输入要改的字符(String)");
                        text = sc.next();
                        System.out.println("字符"+array.set(i,text)+"已更改为"+text);
                        break;
                    }
                case "查看指定位置元素":
                    System.out.println("请输入位置(int)");
                    i = sc.nextInt();
                    if (i < 0 & i >= array.size()) {
                        System.out.println("输入错误位置");
                        break;
                    }
                    else {
                        System.out.println("该位置字符为:"+array.get(i));
                        break;
                    }
                case "在ArrayList末尾添加元素":
                    System.out.println("请输入字符(String)");
                    text = sc.next();
                    System.out.println("添加结果："+array.add(text));
                    break;
                case "在ArrayList中添加元素":
                    System.out.println("请输入位置(int)");
                    i = sc.nextInt();
                    if (i < 0 & i >= array.size()) {
                        System.out.println("输入错误位置");
                        break;
                    }
                    else {
                        System.out.println("请输入要添加的字符(String)");
                        text = sc.next();
                        array.add(i,text);
                        System.out.println("已添加");
                        break;
                    }
                case "帮助":
                    System.out.println("此模式下主要有以下指令：");
                    System.out.println("删除指定位置字符");
                    System.out.println("删除指定字符");
                    System.out.println("修改指定位置字符");
                    System.out.println("查看指定位置元素");
                    System.out.println("在ArrayList末尾添加元素");
                    System.out.println("在ArrayList中添加元素");
                    System.out.println("查看元素");
                    System.out.println("退出ArrayList模式");
                    break;
                case "退出ArrayList模式":
                    w = false;
                    System.out.println("已退出ArrayList模式");
                    break;
                default:
                    System.out.println("错误指令");
            }
        }
    }

    public void math(){
        int i,t;
        double s,d;
        float f;
        boolean w = true;
        Scanner sc = new Scanner(System.in);
        while(w) {
            System.out.println("请输入指令以使用数学方法");
            String input = sc.next();
            switch (input) {
                case "绝对值":
                    System.out.println("请输入一个值(int)");
                    i = sc.nextInt();
                    System.out.println(Math.abs(i));
                    break;
                case "最大值":
                    System.out.println("请输入一个值(double)");
                    s = sc.nextDouble();
                    System.out.println(Math.ceil(s));
                    break;
                case "最小值":
                    System.out.println("请输入一个值(double)");
                    s = sc.nextDouble();
                    System.out.println(Math.floor(s));
                    break;
                case "四舍五入":
                    System.out.println("请输入一个数(float)");
                    f = sc.nextFloat();
                    System.out.println(Math.round(f));
                    break;
                case "max":
                    System.out.println("请输入两个数(int)");
                    i = sc.nextInt();
                    t = sc.nextInt();
                    System.out.println(Math.max(i, t));
                    break;
                case "min":
                    System.out.println("请输入两个数(int)");
                    i = sc.nextInt();
                    t = sc.nextInt();
                    System.out.println(Math.min(i, t));
                    break;
                case "幂":
                    System.out.println("请输入底数和次方数(double)");
                    s = sc.nextDouble();
                    d = sc.nextDouble();
                    System.out.println(Math.pow(s, d));
                    break;
                case "随机数":
                    System.out.println(Math.random());
                    break;
                case "退出":
                    w = false;
                    System.out.println("已退出math模式");
                    break;
                case "帮助":
                    System.out.println("此模式下主要有以下指令：");
                    System.out.println("绝对值");
                    System.out.println("最大值");
                    System.out.println("最小值");
                    System.out.println("四舍五入");
                    System.out.println("max");
                    System.out.println("min");
                    System.out.println("幂");
                    System.out.println("随机数");
                    System.out.println("退出");
                    break;
                default:
                    System.out.println("错误指令");
                    break;
            }
        }
    }

    public void storage(){
        System.out.println("正在存储");
        try {
            File writeName = new File("C:\\Users\\26056\\Desktop\\IDEA\\test\\src\\i\\data.txt");
            if (!writeName.exists()) {
                writeName.createNewFile();
            }
            FileWriter writer = new FileWriter(writeName);
            BufferedWriter out = new BufferedWriter(writer);
            out.write(name);
            out.write("\n");
            out.write(Class);
            out.flush();
            System.out.println("存储已完成");
        }
        catch (IOException e){
            e.printStackTrace();
        }
    }

    public void read() {
        try {
            FileReader f = new FileReader("C:\\Users\\26056\\Desktop\\IDEA\\test\\src\\i\\data.txt");
            BufferedReader bf = new BufferedReader(f);
            String line = bf.readLine();
            name = line;
            line = bf.readLine();
            Class = line;
            bf.close();
            f.close();
        }
        catch (IOException e){
            e.printStackTrace();
        }
    }

    public void classify() {
        char[][] arr = new char[36][2];
        char l, com;
        int i, t, check = 0;
        for (i = 0; i < 36; i++) {
            arr[i][1] = 48;
            arr[i][0] = '空';
        }
        Scanner sc = new Scanner(System.in);
        System.out.println("您需要统计哪个选项？（名字  班级）");
        String input = sc.next();
        if (input.equals("名字")) {
            for (i = 0; i < name.length(); i++) {
                l = name.charAt(i);
                for (t = 0; check == 0 & t < 36; t++) {
                    com = arr[t][0];
                    if (l == com) {
                        arr[t][1] += 1;
                        check = 1;
                    }
                }
                if (check == 0) {
                    for (t = 0; check == 0; t++) {
                        if (arr[t][0] == '空') {
                            arr[t][0] = l;
                            arr[t][1] += 1;
                            check = 1;
                        }
                    }
                }
                check = 0;
            }
            for (t = 0; arr[t][0] != '空'; t++) {
                System.out.println("字符：" + arr[t][0] + "    数量：" + arr[t][1]);
            }
        } else if (input.equals("班级")) {
            for (i = 0; i < Class.length(); i++) {
                l = Class.charAt(i);
                for (t = 0; check == 0; t++) {
                    com = arr[t][0];
                    if (l == com) {
                        arr[t][1] += 1;
                        check = 1;
                    }
                }
                if (check == 0) {
                    for (t = 0; check == 0; t++) {
                        if (arr[t][0] == '空') {
                            arr[t][0] = l;
                            arr[t][1] += 1;
                            check = 1;
                        }
                    }
                }
                check = 0;
            }
            for (t = 0; arr[t][0] != '空'; t++) {
                System.out.println("字符：" + arr[t][0] + "    数量：" + arr[t][1]);
            }
        } else {
            System.out.println("输入错误指令");
        }
    }
}